package sendandreceive;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class Client {
	protected static String host = "127.0.0.1";
	protected static int port = 6000;
	protected static Scanner sc;
	protected static ObjectOutputStream os;
	protected static Socket client;
	protected static String msg = null;
	protected static DataInputStream dis = null;
	protected static ObjectInputStream is;
	public static void main(String[] args) throws UnknownHostException, IOException, ClassNotFoundException {
		//Client c = new Client();
		client = new Socket(host, port);
		if (client.isConnected())
		System.out.println("Cliente Conectado "+host+":"+port);
		dis  = new DataInputStream(System.in);
		os = new ObjectOutputStream(client.getOutputStream());
		is = new ObjectInputStream (client.getInputStream());
		for(;;){
			receive(); 
			send();		
		}			
	}
	static void send() {
			try {
				msg = dis.readLine();
				os.writeObject("Cliente :"+msg);
				os.flush();
				System.out.println("Cliente :"+msg);
			} catch (IOException e) {
				e.printStackTrace();
				}	
	}
	
	static void receive() {
		String servermsg;
		try {
			servermsg = (String)is.readObject();
			System.out.println(servermsg); 
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {		
			e.printStackTrace();
		}
	}
	static void close() throws IOException{
		is.close(); os.close();
	}
}